package com.swsc.solarverse.dao.mapper.forward;

import com.swsc.solarverse.common.mybatis.BasePlusMapper;
import com.swsc.solarverse.dao.entity.forward.ForwardInverterDataDO;
import com.swsc.solarverse.model.StationGenerationPowerBO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author AutoGenerator
 * @since 2022-08-24
 */
@Mapper
public interface ForwardInverterDataMapper extends BasePlusMapper<ForwardInverterDataDO> {
    /**
     * 发电量
     * @param tenantNo
     * @param organNo
     * @return
     */
    StationGenerationPowerBO generationPower(@Param("tenantNo") Integer tenantNo,
                                             @Param("organNo") Integer organNo,
                                             @Param("dataTimeStart") LocalDateTime dataTimeStart,
                                             @Param("dataTimeEnd") LocalDateTime dataTimeEnd
    );

    /**
     * 批量插入数据
     * 不存在插入, 存在则更新
     *
     * @param list
     * @return
     */
    @org.apache.ibatis.annotations.Insert(value = {
            "<script>",
            "INSERT INTO solar_forward_inverter_data (`id`, `tenant_no`, `organ_no`, `device_id`, `device_name`, `voltage`, `electric_current`, `pv_input_power`, `power_generation`, `total_output`, `data_time`, `create_time`) VALUES ",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "(#{item.id}, #{item.tenantNo}, #{item.organNo}, #{item.deviceId}, #{item.deviceName}, #{item.voltage}, #{item.electricCurrent}, #{item.pvInputPower}, #{item.powerGeneration}, #{item.totalOutput},  #{item.dataTime}, #{item.createTime})",
            "</foreach>",
            " ON DUPLICATE KEY UPDATE ",
            "device_name = VALUES (device_name), voltage = VALUES (voltage), electric_current = VALUES (electric_current), ",
            "pv_input_power = VALUES (pv_input_power), power_generation = VALUES (power_generation), ",
            "total_output = VALUES (total_output), ",
            "data_time = VALUES (data_time)",
            "</script>"
    })
    void insertOrUpdateBatch(List<ForwardInverterDataDO> list);
}
